package com.sinba.common.system.action;

import com.opensymphony.xwork2.ActionSupport;

import com.sinba.common.dto.PageDTO;
import com.sinba.common.system.dto.TransactionRecordDTO;
import com.sinba.common.system.service.ITransactionRecordService;
import com.sinba.common.user.dto.RegisterUserDTO;
import com.sinba.common.utils.TranType;

import org.apache.struts2.ServletActionContext;

import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;

@SuppressWarnings( "serial" )
public class TransactionRecordAction
    extends ActionSupport
{
    @Autowired
    private ITransactionRecordService transactionRecordService;
    private PageDTO pageDTO = new PageDTO(  );
    private TransactionRecordDTO trDTO = new TransactionRecordDTO(  );
    private Long[] ids;
    private int page = 1;
    private int rows = 10;
    private String sord;
    private String sidx;

    public TransactionRecordDTO getTrDTO(  )
    {
        return trDTO;
    }

    public void setTrDTO( TransactionRecordDTO trDTO )
    {
        this.trDTO = trDTO;
    }

    public Long[] getIds(  )
    {
        return ids;
    }

    public void setIds( Long[] ids )
    {
        this.ids = ids;
    }

    public int getPage(  )
    {
        return page;
    }

    public void setPage( int page )
    {
        this.page = page;
    }

    public int getRows(  )
    {
        return rows;
    }

    public void setRows( int rows )
    {
        this.rows = rows;
    }

    public String getSord(  )
    {
        return sord;
    }

    public void setSord( String sord )
    {
        this.sord = sord;
    }

    public String getSidx(  )
    {
        return sidx;
    }

    public void setSidx( String sidx )
    {
        this.sidx = sidx;
    }

    public PageDTO getPageDTO(  )
    {
        return pageDTO;
    }

    public void setPageDTO( PageDTO pageDTO )
    {
        this.pageDTO = pageDTO;
    }

    public String findTransactionRecordPager(  )
    {
        int start = ( page - 1 ) * rows;
        trDTO.setStart( start );
        trDTO.setLimit( rows );
        if("充值管理".equals(trDTO.getSearchType())){
        	trDTO.setTransactionTypes(new String[]{TranType.ChongZhi,TranType.KouChu});
        }
        pageDTO = transactionRecordService.findTransactionRecordPager( trDTO, sord, sidx );

        if ( pageDTO != null )
        {
            pageDTO.setPage( page );
            pageDTO.setRows( rows );
        }

        return SUCCESS;
    }

    public String findTransPager(  )
    {
        HttpSession session = ServletActionContext.getRequest(  ).getSession(  );

        if ( session.getAttribute( "loginName" ) != null )
        {
            trDTO.setLoginName( (String) session.getAttribute( "loginName" ) );

            int start = ( page - 1 ) * rows;
            trDTO.setStart( start );
            trDTO.setLimit( rows );
            pageDTO = transactionRecordService.findTransactionRecordPager( trDTO, sord, sidx );

            if ( pageDTO != null )
            {
                pageDTO.setPage( page );
                pageDTO.setRows( rows );
            }
        }

        return "bonus";
    }

    public String saveTrans(  )
    {
        transactionRecordService.saveTrans( trDTO );

        return SUCCESS;
    }

    public String deleteTrans(  )
    {
        transactionRecordService.deleteTrans( ids );

        return SUCCESS;
    }
}
